//package com.fl.ik.controller;
//
//import com.fl.ik.dao.FilmRepository;
//import com.fl.ik.pojo.FilmEntity;
//import org.elasticsearch.index.query.DisMaxQueryBuilder;
//import org.elasticsearch.index.query.QueryBuilder;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.time.Instant;
//import java.time.LocalDateTime;
//import java.time.ZoneId;
//import java.util.Date;
//import java.util.List;
//
//@RestController
//public class TestController {
//
//
//    @Autowired
//    FilmRepository filmRepository;
//    @GetMapping("save")
//    public String save(String des,String name){
//        LocalDateTime localDateTime = LocalDateTime.now();
//        ZoneId zone = ZoneId.systemDefault();
//        Instant instant = localDateTime.atZone(zone).toInstant();
//        Date date = Date.from(instant);
//        FilmEntity filmEntity = new FilmEntity(System.currentTimeMillis(),name,des,date);
//        filmRepository.save(filmEntity);
//        return "success";
//    }
//
//    /**
//     * 拼接搜索条件
//     *
//     * @param name     the name
//     * @return list
//     */
//    @GetMapping("search")
//    public List<FilmEntity> search(String name) {
//        NativeSearchQuery build = new NativeSearchQueryBuilder()
//                .withQuery(structureQuery(name))
//                .build();
//        List<FilmEntity> list = filmRepository.searchSimilar(searchQuery).getContent();
//        return list;
//    }
//
//    /**
//     * 中文、拼音混合搜索
//     *
//     * @param content the content
//     * @return dis max query builder
//     */
////    @GetMapping("search")
//    public DisMaxQueryBuilder structureQuery(String content) {
//        //使用dis_max直接取多个query中，分数最高的那一个query的分数即可
//        DisMaxQueryBuilder disMaxQueryBuilder = QueryBuilders.disMaxQuery();
//        //boost 设置权重,只搜索匹配name和disrector字段
//        QueryBuilder ikNameQuery = QueryBuilders.matchQuery("name", content).boost(2f);
//        QueryBuilder pinyinNameQuery = QueryBuilders.matchQuery("name.pinyin", content);
//        QueryBuilder ikDirectorQuery = QueryBuilders.matchQuery("director", content).boost(2f);
//        disMaxQueryBuilder.add(ikNameQuery);
//        disMaxQueryBuilder.add(pinyinNameQuery);
//        disMaxQueryBuilder.add(ikDirectorQuery);
//        return disMaxQueryBuilder;
//    }
//
//
//
//
//}
